package com.dlyk.web;

import com.dlyk.model.TActivityRemark;
import com.dlyk.model.TClueRemark;
import com.dlyk.query.ActivityRemarkQuery;
import com.dlyk.query.ClueRemarkQuery;
import com.dlyk.result.R;
import com.dlyk.service.ClueRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: ajie
 * @date: 2024/7/28 16:55:59
 * @version: 1.0
 */
@RestController
public class ClueRemarkController {
    @Resource
    private ClueRemarkService clueRemarkService;

    /**
     * @description: 新增线索跟踪记录
     * @params: [clueRemarkQuery, token]
     * @return:
     * @author: ajie
     * @date: 2024/7/28 18:03
     */
    @PostMapping("/api/clue/remark")
    public R addActivityRemark(@RequestBody ClueRemarkQuery clueRemarkQuery,
                               @RequestHeader("Authorization") String token) {
        clueRemarkQuery.setToken(token);
        int save = clueRemarkService.saveClueRemark(clueRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }


    /**
     * @description: 分页查询线索跟踪记录
     * @params: [current, clueId]       
     * @return: 
     * @author: ajie
     * @date: 2024/7/28 18:06
     */
    @GetMapping("/api/clue/remark")
    public R clueRemarkPage(@RequestParam(value = "current",required = false) Integer current,
                                @RequestParam(value = "clueId") Integer clueId){
        ClueRemarkQuery clueRemarkQuery = new ClueRemarkQuery();
        clueRemarkQuery.setClueId(clueId);
        if (current == null){
            current = 1;
        }
        PageInfo<TClueRemark> pageInfo = clueRemarkService.getClueRemarkByPage(current,clueRemarkQuery);
        return R.OK(pageInfo);
    }


    /**
     * @description: 根据id查询线索跟踪记录
     * @params: [id]
     * @return:
     * @author: ajie
     * @date: 2024/7/28 20:06
     */
    @GetMapping("/api/clue/remark/{id}")
    public R clueRemarkById(@PathVariable(value = "id") Integer id ){

        TClueRemark tClueRemark = clueRemarkService.getClueRemarkById(id);
        return R.OK(tClueRemark);
    }


    /**
     * @description: 编辑线索跟踪记录
     * @params: [clueRemarkQuery, token]
     * @return:
     * @author: ajie
     * @date: 2024/7/28 20:25
     */
    @PutMapping("/api/clue/remark")
    public R editClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery,
                                @RequestHeader("Authorization") String token) {
        clueRemarkQuery.setToken(token);
        int update = clueRemarkService.updateClueRemark(clueRemarkQuery);
        return update >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * @description: 根据id删除线索跟踪记录
     * @params: [id]
     * @return:
     * @author: ajie
     * @date: 2024/7/28 20:29
     */
    @DeleteMapping("/api/clue/remark/{id}")
    public R delClueRemark(@PathVariable(value = "id") Integer id){
        int del = clueRemarkService.delClueRemarkById(id);
        return del >= 1 ? R.OK() : R.FAIL();
    }
}
